package main

import (
	"fmt"
	"log"
	"note/docker/container"

	"github.com/urfave/cli"
)

var (
	runCommand = cli.Command{
		Name:  "run",
		Usage: `create a conteainer with namespace and cgroups limit docker run -ti `,

		Flags: []cli.Flag{
			cli.BoolFlag{
				Name:  "ti",
				Usage: "enable tty",
			},
		},
		/*
			这里是run 命令执行的真正函数。
			1. 判断参数是否包含command
			2. 获取用户指定的command
			3 . 调用Run function 去准备启动容器
		*/
		Action: func(ctx *cli.Context) error {
			if len(ctx.Args()) < 1 {
				return fmt.Errorf("Missing container command")
			}

			cmd := ctx.Args().Get(0)
			tty := ctx.Bool("ti")
			Run(tty, cmd)
			return nil
		},
	}

	initCommand = cli.Command{
		Name:  "init",
		Usage: "init container process run user ",

		Action: func(ctx *cli.Context) error {
			log.Println("init come on ")
			cmd := ctx.Args().Get(0)
			return container.RunContainerInitProcess(cmd, nil)
		},
	}
)
